package cn.edu.zafu.bigdata.cccnnn.worksix.TCP;

import java.io.*;
import java.net.*;

public class MyClient {
    public static void main(String[] args) {
        try {
            int port = 8888;
            String hostname = "127.0.0.1"; // 这里需要替换为服务器的实际地址
            Socket socket = new Socket(hostname, port);

            PrintWriter out = new PrintWriter(socket.getOutputStream());
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            BufferedReader sin = new BufferedReader(new InputStreamReader(System.in));

            String s;
            do {
                s = sin.readLine();
                out.println(s);
                out.flush();
                if (!s.equals("bye")) {
                    System.out.println("response: " + in.readLine());
                }
            } while (!s.equals("bye")); // 循环直到用户输入"bye"

            System.out.println("The connection is closing.");
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}